package bamboo.design_pattern.chap20_iter.book;

import java.util.ArrayList;

/**
 * @Author: fulw
 * @Date: 2021/12/21 11:25
 */
public class ProjectIterator implements IProjectIterator {
    /**
     * 所有的项目都放在ArrayList中
     */
    private ArrayList<IProject> projectList = new ArrayList<IProject>();
    private int currentItem = 0;

    /**
     * 构造函数传入projectList
     *
     * @param projectList
     */
    public ProjectIterator(ArrayList<IProject> projectList) {
        this.projectList = projectList;
    }

    /**
     * 判断是否还有元素，必须实现
     *
     * @return
     */
    public boolean hasNext() {
        //定义一个返回值
        boolean b = true;
        if (this.currentItem >= projectList.size() || this.projectList.get(this.currentItem) == null) {
            b = false;
        }
        return b;
    }

    /**
     * 取得下一个值
     *
     * @return
     */
    public IProject next() {
        return this.projectList.get(this.currentItem++);
    }

    public void remove() {

    }

}
